package com.playball.lottery.frm.buyhall;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.json.JSONTokener;

import android.content.Context;
import android.content.Intent;
import android.graphics.drawable.BitmapDrawable;
import android.os.AsyncTask;
import android.os.Bundle;
import android.text.Html;
import android.text.TextUtils;
import android.util.Log;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.BaseExpandableListAdapter;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout.LayoutParams;
import android.widget.ListView;
import android.widget.PopupWindow;
import android.widget.RelativeLayout;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;

import com.playball.lottery.R;
import com.playball.lottery.ApplicationData;
import com.playball.lottery.JddMainActivity;
import com.playball.lottery.base.BaseActivity;
import com.playball.lottery.customview.BaseGroupAdapter2;
import com.playball.lottery.customview.ChildDTO;
import com.playball.lottery.customview.GroupDTO;
import com.playball.lottery.customview.ShowTipDialog;
import com.playball.lottery.frm.help.CaiPiaoHelp;
import com.playball.lottery.frm.kjinfo.KjinfoBDResult;
import com.playball.lottery.frm.yhzx.BetRecordActivity;
import com.playball.lottery.frm.yhzx.LoginActivity;
import com.playball.lottery.nt.GetRequestParams;
import com.playball.lottery.util.AppUtils;
import com.playball.lottery.util.ConvertJsonToList;
import com.playball.lottery.util.DateUtil;
import com.playball.lottery.util.DefConstants;
import com.playball.lottery.util.JCZQUtil;
import com.playball.lottery.util.LotConstants;


/**
 * 北京单场玩法购彩操作界面
 * 
 * @author zhoujun
 * 
 */
public class BDActivity extends BaseActivity implements Serializable, DefConstants {
	/** 上下文内容 */
	private Context context = null;
	private static final long serialVersionUID = 1L;

	private List<ChildDTO> str_childs;

	/**
	 * 北单的展开列表的适配器
	 */
	private static BaseGroupAdapter2 bdlist_adapter = null;

	/**
	 * 北单的展开列表
	 */
	private ListView bd_list;
	// private static List<Map<String, Object>> issueData;
	private static List<Map<String, Object>> matchData;
	/** 期号 */
	public String issueName; // 期号名称
	// public String wkName;// 周几
	// public String mCount;// 几场
	 public String issueID;// 其次ID

	public String mId;// 赛事编号
	public String nMm;// 赛事类型
	public String BgColor;// 赛事颜色
	public String eTime;// 截至时间
	public String hTeam;// 主队
	public String eQ;// 让球
	public String vTeam;// 客队
	/** 让球胜平负SP值 */
	public String sPRqspf;
	/** 半全场SP值 */
	public String sPBQC;
	/** 总进球SP值 */
	public String sPZJQ;//
	/** 上下单双SP值 */
	public String sPBDsxds;//
	/** 比分主胜SP值 */
	public String sPBFS;// 比分主胜SP值
	/** 比分平SP值 */
	public String sPBFP;// 比分平SP值
	/** 比分主负SP值 */
	public String sPBFF;// 比分主负SP值

	public boolean str_sbtn;// 零时胜
	public boolean str_fbtn;// 零时负
	public boolean str_pbtn;// 零时平

	public boolean str_xsbtn;// 零时下双

	private PopupWindow m_popupWindow;

	/** 菜单弹出框 */
	private PopupWindow menu_popupWindow;
	/** 菜单弹出框 */
	private View menutypeview;
	private TextView top_title_tvplaytype;

	// public ShowTipDialog showDialog = new ShowTipDialog();

	TextView clear_bd_button, submit_bd_button;

	TextView tv_selectNum;

	TextView bottom_tv_tips;

	/** 头部下拉选择框 */
	private Spinner spinnerzq;
	/** 北单玩法 */
	private String strBDWF = "RQSPF";
	Date bjCurrTime = null;
	// LoadIssueInfo loadIssueInfo;
	// LoadIssueDetail loadIssueDetail;
	AsyncLoader asyncloader;
	public long randonTimeStamp;

	private Button ll_bd_btn_cancle;

	private String strLot = "让球胜平负";
	
	private View noDataView ;
	/** 判断是否从推送通知过来 */
	private Boolean ifPush;
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		this.context = this;
		randonTimeStamp = System.currentTimeMillis();
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.jdd_bd);
		// 初始化表单
		initView();
		tv_selectNum = (TextView) findViewById(R.id.bottom_tv_select_match);

		bottom_tv_tips = (TextView) findViewById(R.id.bottom_tv_tips);
		bottom_tv_tips.setText("请至少选择1场比赛");
		ifPush = getIntent().getBooleanExtra("ifPush", false);
		loadData(randonTimeStamp);
		tv_selectNum.setText(Html.fromHtml("已经选择" + "<font color=#a50000>" + 0 + "</font>" + "场比赛"));
		// 清空
		ll_bd_btn_cancle.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				if (ApplicationData.getInstance().getList_jcdto().size() >= 1) {
					clearData();
			/*		MyDialog.Builder dialog = new MyDialog.Builder(BDActivity.this);
					dialog.setTitle("清空号码提示");
					dialog.setMessage("清空后您已选择的号码列表将会清空，确认继续?");
					dialog.setPositiveButton("确定", new DialogInterface.OnClickListener() {
						@Override
						public void onClick(DialogInterface dialog, int which) {
							clearData();
							dialog.cancel();
						}
					});
					dialog.setNegativeButton("取消", new DialogInterface.OnClickListener() {
						@Override
						public void onClick(DialogInterface dialog, int which) {
							dialog.cancel();
						}
					}).create().show();*/
				} else {
					Toast.makeText(BDActivity.this, R.string.bdactivity_1, Toast.LENGTH_SHORT).show();
				}
			}
		});

		// 提交按钮
		submit_bd_button.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				bdSubmit();
			}
		});

	}

	public void bdSubmit(){
		
		if (checkUserLogin()) {
			if (ApplicationData.getInstance().getList_jcdto().size() > 0) {
				if (ApplicationData.getInstance().getList_jcdto().size() < 16) {
					Intent intent = new Intent();
					intent.putExtra("Activity", "BDActivity");
					intent.putExtra("list_jcdto", ApplicationData.getInstance().getList_jcdto());
					intent.putExtra("IssueID", issueID);
					intent.putExtra("IssueName", issueName);
					intent.putExtra("strBDWF", strBDWF);
					intent.setClass(BDActivity.this, BDxhlbActivity.class);
					BDActivity.this.startActivityForResult(intent, REQ_CODE_BD);
				} else {
					Toast.makeText(BDActivity.this, R.string.bdactivity_2, Toast.LENGTH_SHORT).show();
				}
			} else {
				Toast.makeText(BDActivity.this, R.string.bdactivity_3, Toast.LENGTH_SHORT).show();
			}
		} else {
			Intent intent = new Intent();
			intent.setClass(BDActivity.this, LoginActivity.class);
			startActivityForResult(intent, REQ_CODE_BD_LOGIN);
		}
		
	}
	
	public void onResume() {
		super.onResume();
		
	}

	public void onPause() {
		super.onPause();
		
	}

	/** 加载数据 */
	private void loadData(long s) {
		AsyncLoader task = new AsyncLoader(s);
		String[] parms = new String[2];
		parms[0] = "205";
		JSONObject jsob = new JSONObject();
		parms[1] = jsob.toString();
		task.execute(parms);
	}

	/**
	 * 获取数据
	 * 
	 * @author Liu
	 * 
	 */
	class AsyncLoader extends AsyncTask<String, Integer, String> {// 继承AsyncTask
		private long snap;
		private ShowTipDialog showdialog = new ShowTipDialog();

		// 1.准备运行
		protected void onPreExecute() {
			showdialog.showDialog(BDActivity.this);
		}

		public AsyncLoader(long s) {
			snap = s;
		}

		@Override
		protected String doInBackground(String... params) {
			String strResult;
			String action = params[0];
			strResult = GetRequestParams.getRequestResultKjInfo(params[1], action, BDActivity.this);
			return strResult;
		}

		protected void onPostExecute(String result) {

			super.onPostExecute(result);
			if (snap != randonTimeStamp) {
				return;
			}
			if (!AppUtils.isBlank(result)) {
				String matches;
				try {
					JSONTokener jsonParser = new JSONTokener(result);
					JSONObject js = (JSONObject) jsonParser.nextValue();
					JSONArray array = new JSONArray(js.getString("Data"));
					if (array.length() == 0) {
						showdialog.closeDialog();
						noDataView.setVisibility(View.VISIBLE);
						return ;	
					}
					JSONObject data = array.getJSONObject(0);
					issueName = data.getString("issue").toString().trim();
					issueID = data.getString("ID").toString().trim();
					matches = data.getJSONArray("Matches").toString();
				} catch (JSONException e) {
					e.printStackTrace();
					matches = "";
				}
				if ("".equals(matches))
					return;
				matchData = ConvertJsonToList.getList(matches);
				List<ChildDTO> childs = new ArrayList<ChildDTO>();
				if (null == str_childs) {
					str_childs = new ArrayList<ChildDTO>();
				}
				if (matchData.size() > 0)
					for (int j = 0; j < matchData.size(); j++) {

						mId = matchData.get(j).get("MID").toString();
						nMm = matchData.get(j).get("NMm").toString();// 赛事类型
						BgColor=matchData.get(j).get("BgColor").toString();// 赛事颜色
						eTime = matchData.get(j).get("ETime").toString().replaceAll("/", "-");// 截至时间
						hTeam = matchData.get(j).get("HTeam").toString();// 主队
						eQ = matchData.get(j).get("Rq").toString();// 让球
						vTeam = matchData.get(j).get("VTeam").toString();// 让球
						sPRqspf = matchData.get(j).get("SpRQSPF").toString();// 胜平负SP值

						// sPBDsxds =
						// newmatchData.get(j).get("SpSXDS").toString();//
						// 上下单双SP值
						// //上下单双服务器SP顺序与正常顺序相反，先转换一步前后顺序,变成上单 上双，下单 下双依次顺序SP值队列
						String sxds = matchData.get(j).get("SpSXDS").toString();// 上下单双SP值
						String[] temp1 = sxds.split("\\|");
						if (temp1.length == 4) {
							sPBDsxds = temp1[3] + "," + temp1[2] + "," + temp1[1] + "," + temp1[0];
						} else {
							Log.v("bdActivity", "getMatchinfo sxds= " + sxds);
							sPBDsxds = "";
						}

						sPBQC = matchData.get(j).get("SpBQC").toString();// 半全场SP值
						sPZJQ = matchData.get(j).get("SpZJQ").toString();// 总进球SP值
						// 如果相应sp值数据为空，仍然可以选择，赋值为0
						if (sPRqspf.equals("")) {
							sPRqspf = "0.00,0.00,0.00";
						}
						if (sPBDsxds.equals("")) {
							sPBDsxds = "0.00,0.00,0.00,0.00";
						}
						if (sPBQC.equals("")) {
							Log.v("bd", "getmatchinfo 半全场sp为空    mId= " + mId + " ,sPBQC=" + sPBQC + " ,hTeam=" + hTeam);
							sPBQC = "0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00";
						}
						if (sPZJQ.equals("")) {
							sPZJQ = "0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00";
						}

						String spBF = "";
						if (!matchData.get(j).get("SpBF").toString().equals("")) {
							spBF = JCZQUtil.changeBDBF3(matchData.get(j).get("SpBF").toString());
							if (spBF.split(",").length >= 2) {
								sPBFS = spBF.split(",")[0];
								sPBFP = spBF.split(",")[1];
								sPBFF = spBF.split(",")[2];
							}
						} else {
							sPBFS = "0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00";
							sPBFP = "0.00,0.00,0.00,0.00,0.00";
							sPBFF = "0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00";
						}

						ChildDTO child = new ChildDTO();
						child.setmId(mId);
						child.setnMm(nMm);
						child.setBgColor(BgColor);
						child.seteTime(eTime);
						child.sethTeam(hTeam);
						child.seteQ(eQ);
						child.setvTeam(vTeam);

						if ((strBDWF.equals("RQSPF"))) {
							child.setsPRqspf(sPRqspf.replace("|", "-"));
							child.setStr_sbtn(false);
							child.setStr_fbtn(false);
							child.setStr_pbtn(false);
						} else if ((strBDWF.equals("SXDS"))) {
							child.setsPBDsxds(sPBDsxds.replace(",", "-"));
							child.setStr_sbtn(false);
							child.setStr_fbtn(false);
							child.setStr_pbtn(false);
							child.setStr_xsbtn(false);
						} else if (strBDWF.equals("BQC")) {
							// 半全场赛果gridview是否显示
							child.setShowBQCGrid(false);
							child.setsPbqc(sPBQC);
							child.setStr_sbtn(false);
							// 半全场赛果gridview按钮状态初始化
							List<String> list_gridview_selectstate = new ArrayList<String>();
							for (int k = 0; k < 9; k++) {// 半全场9中赛果
								list_gridview_selectstate.add("false");
							}
							child.setList_bqcgridview_selectstate(list_gridview_selectstate);
							// 半全场赛果gridview按钮SP list初始化
							List<String> list_gridview_selectsp = new ArrayList<String>();
							for (int k = 0; k < 9; k++) {// 半全场9中赛果sp
								list_gridview_selectsp.add("0");
							}
							child.setList_bqcgridview_selectsp(list_gridview_selectsp);
							child.setBtnBQCcontent("点击弹出下拉列表");
						} else if (strBDWF.equals("ZJQ")) {
							child.setsPzjq(sPZJQ);
							// 总进球gridview按钮状态初始化
							List<String> list_gridview_selectstate = new ArrayList<String>();
							for (int k = 0; k < 8; k++) {// 总进球8种赛果
								list_gridview_selectstate.add("false");
							}
							child.setList_zjqgridview_selectstate(list_gridview_selectstate);
							// 总进球gridview按钮sp list初始化
							List<String> list_gridview_selectsp = new ArrayList<String>();
							for (int k = 0; k < 8; k++) {// 总进球8种赛果sp
								list_gridview_selectsp.add("0");
							}
							child.setList_zjqgridview_selectsp(list_gridview_selectsp);
						} else if (strBDWF.equals("BF")) {
							// 比分主胜gridview是否显示
							child.setShowBFS(false);
							child.setShowBFP(false);
							child.setShowBFF(false);
							// 存储比分SP值
							child.setsPbfs(sPBFS);
							child.setsPbfp(sPBFP);
							child.setsPbff(sPBFF);
							// 设置按钮选择状态为未选择
							child.setStr_sbtn(false);
							child.setStr_fbtn(false);
							child.setStr_pbtn(false);
							// 比分主胜gridview按钮状态初始化
							List<String> list_bfsgridview_selectstate = new ArrayList<String>();
							for (int k = 0; k < 10; k++) {// 比分主胜10种赛果
								list_bfsgridview_selectstate.add("false");
							}
							child.setList_bfsgridview_selectstate(list_bfsgridview_selectstate);
							// 比分平gridview按钮状态初始化
							List<String> list_bfpgridview_selectstate = new ArrayList<String>();
							for (int k = 0; k < 5; k++) {// 比分平5种赛果
								list_bfpgridview_selectstate.add("false");
							}
							child.setList_bfpgridview_selectstate(list_bfpgridview_selectstate);
							// 比分主负gridview按钮状态初始化
							List<String> list_bffgridview_selectstate = new ArrayList<String>();
							for (int k = 0; k < 10; k++) {// 比分主负10种赛果
								list_bffgridview_selectstate.add("false");
							}
							child.setList_bffgridview_selectstate(list_bffgridview_selectstate);
							// 设置按钮初始文字内容
							child.setBtnbfscontent("主胜");
							child.setBtnbfpcontent("平局");
							child.setBtnbffcontent("主负");
							// 比分sp值选择list初始化
							List<String> list_bfsgridview_selectsp = new ArrayList<String>();
							for (int k = 0; k < 10; k++) {// 比分主胜10种赛果SP
								list_bfsgridview_selectsp.add("0");
							}
							child.setList_bfsgridview_selectsp(list_bfsgridview_selectsp);

							List<String> list_bfpgridview_selectsp = new ArrayList<String>();
							for (int k = 0; k < 5; k++) {// 比分平5种赛果SP
								list_bfpgridview_selectsp.add("0");
							}
							child.setList_bfpgridview_selectsp(list_bfpgridview_selectsp);

							List<String> list_bffgridview_selectsp = new ArrayList<String>();
							for (int k = 0; k < 10; k++) {// 比分主负10种赛果SP
								list_bffgridview_selectsp.add("0");
							}
							child.setList_bffgridview_selectsp(list_bffgridview_selectsp);
						}

						childs.add(child);
						str_childs.add(child);
					}

				bdlist_adapter = new BaseGroupAdapter2(BDActivity.this, str_childs, strBDWF);
				bd_list.setAdapter(bdlist_adapter); // 绑定视图－适配器
			} else {
				Toast.makeText(BDActivity.this, getString(R.string.problem_01), Toast.LENGTH_LONG).show();
			}
			showdialog.closeDialog();
		}

	}

	/*
	 * public String getWkByData(String data) { Calendar calendar =
	 * Calendar.getInstance(); int year = Integer.parseInt(data.substring(0,
	 * 2)); int month = Integer.parseInt(data.substring(2, 4)); int day =
	 * Integer.parseInt(data.substring(4)); calendar.set(year, month - 1,
	 * day);// 设置当前时间,月份是从0月开始计算 int number =
	 * calendar.get(Calendar.DAY_OF_WEEK);// 星期表示1-7，是从星期日开始， String[] str = {
	 * "", "星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六", }; //
	 * System.out.println(str[number]); String myWeek = "1"; switch (number) {
	 * case 1: myWeek = "7"; break; case 2: myWeek = "1"; break; case 3: myWeek
	 * = "2"; break; case 4: myWeek = "3"; break; case 5: myWeek = "4"; break;
	 * case 6: myWeek = "5"; break; case 7: myWeek = "6"; break; default: break;
	 * } return myWeek; }
	 */

	public void getMatchData() throws Exception {

		tv_selectNum.setText(Html.fromHtml("已经选择" + "<font color=#a50000>" + 0 + "</font>" + "场比赛"));

		if (bjCurrTime != null) {
			List<Map<String, Object>> deleteMatches = new ArrayList<Map<String, Object>>();
			for (int j = 0; j < matchData.size(); j++) {
				String time = matchData.get(j).get("ETime").toString();
				Date date = new Date(time);
				if (bjCurrTime.after(date)) {
					deleteMatches.add(matchData.get(j));
				}
			}
			if (deleteMatches.size() > 0) {
				matchData.removeAll(deleteMatches);
			}
		}

		List<Map<String, Object>> newmatchData = matchData;

		List<ChildDTO> childs = new ArrayList<ChildDTO>();
		str_childs.clear();
		for (int j = 0; j < newmatchData.size(); j++) {

			mId = matchData.get(j).get("MID").toString();
			nMm = matchData.get(j).get("NMm").toString();// 赛事类型
			BgColor=matchData.get(j).get("BgColor").toString();// 赛事颜色
			eTime = matchData.get(j).get("ETime").toString().replaceAll("/", "-");// 截至时间
			hTeam = matchData.get(j).get("HTeam").toString();// 主队
			eQ = matchData.get(j).get("Rq").toString();// 让球
			vTeam = matchData.get(j).get("VTeam").toString();// 让球
			sPRqspf = matchData.get(j).get("SpRQSPF").toString();// 胜平负SP值

			// sPBDsxds = newmatchData.get(j).get("SpSXDS").toString();//
			// 上下单双SP值
			// //上下单双服务器SP顺序与正常顺序相反，先转换一步前后顺序,变成上单 上双，下单 下双依次顺序SP值队列
			String sxds = newmatchData.get(j).get("SpSXDS").toString();// 上下单双SP值
			String[] temp1 = sxds.split("\\|");
			if (temp1.length == 4) {
				sPBDsxds = temp1[3] + "," + temp1[2] + "," + temp1[1] + "," + temp1[0];
			} else {
				Log.v("bdActivity", "getMatchinfo sxds= " + sxds);
				sPBDsxds = "";
			}
			sPBQC = matchData.get(j).get("SpBQC").toString().replace("|", ",");// 半全场SP值
			sPZJQ = matchData.get(j).get("SpZJQ").toString().replace("|", ",");// 总进球SP值
			// 如果相应sp值数据为空，仍然可以选择，赋值为0
			if (sPRqspf.equals("")) {
				sPRqspf = "0.00,0.00,0.00";
			}
			if (sPBDsxds.equals("")) {
				sPBDsxds = "0.00,0.00,0.00,0.00";
			}
			if (sPBQC.equals("")) {
				Log.v("bd", "getmatchinfo 半全场sp为空    mId= " + mId + " ,sPBQC=" + sPBQC + " ,hTeam=" + hTeam);
				sPBQC = "0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00";
			}
			if (sPZJQ.equals("")) {
				sPZJQ = "0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00";
			}

			String spBF = "";
			if (!matchData.get(j).get("SpBF").toString().equals("")) {
				spBF = JCZQUtil.changeBDBF3(matchData.get(j).get("SpBF").toString());
				if (spBF.split(",").length >= 2) {
					sPBFS = spBF.split(",")[0];
					sPBFP = spBF.split(",")[1];
					sPBFF = spBF.split(",")[2];
				}
			} else {
				sPBFS = "0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00";
				sPBFP = "0.00,0.00,0.00,0.00,0.00";
				sPBFF = "0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00";
			}
			ChildDTO child = new ChildDTO();
			child.setmId(mId);
			child.setnMm(nMm);
			child.setBgColor(BgColor);
			child.seteTime(eTime);
			child.sethTeam(hTeam);
			child.seteQ(eQ);
			child.setvTeam(vTeam);

			if ((strBDWF.equals("RQSPF"))) {
				child.setsPRqspf(sPRqspf.replace("|", "-"));
				child.setStr_sbtn(false);
				child.setStr_fbtn(false);
				child.setStr_pbtn(false);
			} else if ((strBDWF.equals("SXDS"))) {
				child.setsPBDsxds(sPBDsxds.replace(",", "-"));
				child.setStr_sbtn(false);
				child.setStr_fbtn(false);
				child.setStr_pbtn(false);
				child.setStr_xsbtn(false);
			} else if (strBDWF.equals("BQC")) {
				// 半全场赛果gridview是否显示
				child.setShowBQCGrid(false);
				child.setsPbqc(sPBQC);
				child.setStr_sbtn(false);
				// 半全场赛果gridview按钮状态初始化
				List<String> list_gridview_selectstate = new ArrayList<String>();
				for (int k = 0; k < 9; k++) {// 半全场9中赛果
					list_gridview_selectstate.add("false");
				}
				child.setList_bqcgridview_selectstate(list_gridview_selectstate);
				// 半全场赛果gridview按钮SP list初始化
				List<String> list_gridview_selectsp = new ArrayList<String>();
				for (int k = 0; k < 9; k++) {// 半全场9中赛果sp
					list_gridview_selectsp.add("0");
				}
				child.setList_bqcgridview_selectsp(list_gridview_selectsp);
				child.setBtnBQCcontent("点击弹出下拉列表");
			} else if (strBDWF.equals("ZJQ")) {
				child.setsPzjq(sPZJQ);
				// 总进球gridview按钮状态初始化
				List<String> list_gridview_selectstate = new ArrayList<String>();
				for (int k = 0; k < 8; k++) {// 总进球8种赛果
					list_gridview_selectstate.add("false");
				}
				child.setList_zjqgridview_selectstate(list_gridview_selectstate);
				// 总进球gridview按钮sp list初始化
				List<String> list_gridview_selectsp = new ArrayList<String>();
				for (int k = 0; k < 8; k++) {// 总进球8种赛果sp
					list_gridview_selectsp.add("0");
				}
				child.setList_zjqgridview_selectsp(list_gridview_selectsp);
			} else if (strBDWF.equals("BF")) {
				// 比分主胜gridview是否显示
				child.setShowBFS(false);
				child.setShowBFP(false);
				child.setShowBFF(false);
				// 存储比分SP值
				child.setsPbfs(sPBFS);
				child.setsPbfp(sPBFP);
				child.setsPbff(sPBFF);
				// 设置按钮选择状态为未选择
				child.setStr_sbtn(false);
				child.setStr_fbtn(false);
				child.setStr_pbtn(false);
				// 比分主胜gridview按钮状态初始化
				List<String> list_bfsgridview_selectstate = new ArrayList<String>();
				for (int k = 0; k < 10; k++) {// 比分主胜10种赛果
					list_bfsgridview_selectstate.add("false");
				}
				child.setList_bfsgridview_selectstate(list_bfsgridview_selectstate);
				// 比分平gridview按钮状态初始化
				List<String> list_bfpgridview_selectstate = new ArrayList<String>();
				for (int k = 0; k < 5; k++) {// 比分平5种赛果
					list_bfpgridview_selectstate.add("false");
				}
				child.setList_bfpgridview_selectstate(list_bfpgridview_selectstate);
				// 比分主负gridview按钮状态初始化
				List<String> list_bffgridview_selectstate = new ArrayList<String>();
				for (int k = 0; k < 10; k++) {// 比分主负10种赛果
					list_bffgridview_selectstate.add("false");
				}
				child.setList_bffgridview_selectstate(list_bffgridview_selectstate);
				// 设置按钮初始文字内容
				child.setBtnbfscontent("主胜");
				child.setBtnbfpcontent("平局");
				child.setBtnbffcontent("主负");
				// 比分sp值选择list初始化
				List<String> list_bfsgridview_selectsp = new ArrayList<String>();
				for (int k = 0; k < 10; k++) {// 比分主胜10种赛果SP
					list_bfsgridview_selectsp.add("0");
				}
				child.setList_bfsgridview_selectsp(list_bfsgridview_selectsp);

				List<String> list_bfpgridview_selectsp = new ArrayList<String>();
				for (int k = 0; k < 5; k++) {// 比分平5种赛果SP
					list_bfpgridview_selectsp.add("0");
				}
				child.setList_bfpgridview_selectsp(list_bfpgridview_selectsp);

				List<String> list_bffgridview_selectsp = new ArrayList<String>();
				for (int k = 0; k < 10; k++) {// 比分主负10种赛果SP
					list_bffgridview_selectsp.add("0");
				}
				child.setList_bffgridview_selectsp(list_bffgridview_selectsp);
			}

			childs.add(child);
			str_childs.add(child);
		}
		bdlist_adapter.notifyDataSetChanged();
	}

	// 初始化
	public void initView() {
		bd_list = (ListView) findViewById(R.id.prelv_matches);

		ll_bd_btn_cancle = (Button) findViewById(R.id.buy_ssqxh_Buttondel);
		// clear_bd_button = (TextView) findViewById(R.id.bottom_left_btn);
		submit_bd_button = (TextView) findViewById(R.id.bottom_right_btn);
		noDataView = findViewById(R.id.no_data);
		titleBar();

	}

	// 方法由ExpandableListView适配器来调用,转存至全局变量list来显示
	@SuppressWarnings("all")
	public void initMapData(List<ChildDTO> list_jcdto, String strBDWF) {
		if (strBDWF.equals("RQSPF") || (strBDWF.equals("SXDS"))) {
			if (ApplicationData.getInstance().getList_jcdto().size() != 0) {
				ApplicationData.getInstance().getList_jcdto().clear();
			}
			for (ChildDTO list_child : list_jcdto) {
				if (!list_child.str_sp.equals("")) {
					ApplicationData.getInstance().getList_jcdto().add(list_child);
				}
			}
		} else if (strBDWF.equals("BQC")) {
			// 比较APP和传过来的list,如果MID一样，需要删除旧的，添加新的;如果MID不一样，需要直接添加新的
			// 定义一个删除时零时的list
			List<ChildDTO> delList = new ArrayList();
			// // 判断第一次进来全局变量里有没有值.
			if (ApplicationData.getInstance().getList_jcdto().size() != 0) {
				for (ChildDTO app_child : ApplicationData.getInstance().getList_jcdto()) {
					for (ChildDTO list_child : list_jcdto) {
						String app_mid = "";
						String list_mid = "";
						if (app_child.getmId().equals(list_child.getmId())) {
							delList.add(app_child);
						}
					}
				}
				ApplicationData.getInstance().getList_jcdto().removeAll(delList);
			}
			for (ChildDTO list_child : list_jcdto) {
				// 全局变量存贮选择的赛事
				if (!list_child.getBtnBQCcontent().equals("点击弹出下拉列表")) {
					ApplicationData.getInstance().getList_jcdto().add(list_child);
				}
			}

		} else if (strBDWF.equals("ZJQ")) {
			// 比较APP和传过来的list,如果MID一样，需要删除旧的，添加新的;如果MID不一样，需要直接添加新的
			// 定义一个删除时零时的list
			List<ChildDTO> delList = new ArrayList();
			// // 判断第一次进来全局变量里有没有值.
			if (ApplicationData.getInstance().getList_jcdto().size() != 0) {
				for (ChildDTO app_child : ApplicationData.getInstance().getList_jcdto()) {
					for (ChildDTO list_child : list_jcdto) {
						String app_mid = "";
						String list_mid = "";
						if (app_child.getmId().equals(list_child.getmId())) {
							delList.add(app_child);
						}
					}
				}
				ApplicationData.getInstance().getList_jcdto().removeAll(delList);
			}
			for (ChildDTO list_child : list_jcdto) {
				// 全局变量存贮选择的赛事
				if (!list_child.getSelectZJQCG().equals("")) {
					ApplicationData.getInstance().getList_jcdto().add(list_child);
				}
			}
		} else if (strBDWF.equals("BF")) {
			// 比较APP和传过来的list,如果MID一样，需要删除旧的，添加新的;如果MID不一样，需要直接添加新的
			// 定义一个删除时零时的list
			List<ChildDTO> delList = new ArrayList();
			// // 判断第一次进来全局变量里有没有值.
			if (ApplicationData.getInstance().getList_jcdto().size() != 0) {
				for (ChildDTO app_child : ApplicationData.getInstance().getList_jcdto()) {
					for (ChildDTO list_child : list_jcdto) {
						String app_mid = "";
						String list_mid = "";
						if (app_child.getmId().equals(list_child.getmId())) {
							delList.add(app_child);
						}
					}
				}
				ApplicationData.getInstance().getList_jcdto().removeAll(delList);
			}
			for (ChildDTO list_child : list_jcdto) {
				// 全局变量存贮选择的赛事
				if (!((list_child.getBtnbfscontent() + list_child.getBtnbfpcontent() + list_child.getBtnbffcontent())
						.equals("主胜平局主负"))) {
					ApplicationData.getInstance().getList_jcdto().add(list_child);
				}
			}
		}

		tv_selectNum.setText(Html.fromHtml("已经选择" + "<font color=#a50000>"
				+ ApplicationData.getInstance().getList_jcdto().size() + "</font>" + "场比赛"));
		bdlist_adapter.notifyDataSetChanged();
	}

	/**
	 * 获取当前期次信息
	 * 
	 * @param strResult
	 * @return
	 */
	/*
	 * private List<Map<String, Object>> getCurrentlData(String strResult) {
	 * List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
	 * try { JSONTokener jsonParser = new JSONTokener(strResult); JSONObject js
	 * = (JSONObject) jsonParser.nextValue(); list =
	 * ConvertJsonToList.getList(js.getString("Data").toString()); } catch
	 * (JSONException e) { // 异常处理代码 Log.e("error", e.toString()); } return
	 * list; }
	 */

	/**
	 * 设置按钮显示文字为选择的赛事结果
	 * 
	 */
	public static void btnChildNamechange() {
		bdlist_adapter.notifyDataSetChanged();
	}

	// TitleBar标题栏
	public void titleBar() {
		// Title信息(返回+Title)

		TextView back = (TextView) findViewById(R.id.top_title_back);
		back.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				onKeyDown(KeyEvent.KEYCODE_BACK, null);
			}
		});
		top_title_tvplaytype = (TextView) findViewById(R.id.top_title_tvbd);
		top_title_tvplaytype.setText(strLot);
		/**
		 * 更改头部选项框
		 */

		top_title_tvplaytype.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				LayoutInflater inflater = LayoutInflater.from(BDActivity.this);
				menutypeview = inflater.inflate(R.layout.bd_topmenulink, null);
				menu_popupWindow = new PopupWindow(menutypeview, LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
				menu_popupWindow.setBackgroundDrawable(new BitmapDrawable());

				menu_popupWindow.setFocusable(true);
				menu_popupWindow.setTouchable(true);
				menu_popupWindow.setOutsideTouchable(false);

				menu_popupWindow.showAtLocation(menutypeview, Gravity.CENTER | Gravity.TOP, 0, 0);
				menu_popupWindow.showAsDropDown(top_title_tvplaytype);
				menutypeview.setOnClickListener(new View.OnClickListener() {
					public void onClick(View v) {
						// TODO Auto-generated method stub
						menu_popupWindow.dismiss();
					}
				});
				setBtnOnClickTopMenu(R.id.bd_topmenulink_Button1);
				setBtnOnClickTopMenu(R.id.bd_topmenulink_Button2);
				setBtnOnClickTopMenu(R.id.bd_topmenulink_Button3);
				setBtnOnClickTopMenu(R.id.bd_topmenulink_Button4);
				setBtnOnClickTopMenu(R.id.bd_topmenulink_Button5);
				if (strBDWF.equals("RQSPF")) {
					((Button) menutypeview.findViewById(R.id.bd_topmenulink_Button1)).setSelected(true);
				} else if (strBDWF.equals("ZJQ")) {
					((Button) menutypeview.findViewById(R.id.bd_topmenulink_Button2)).setSelected(true);
				} else if (strBDWF.equals("SXDS")) {
					((Button) menutypeview.findViewById(R.id.bd_topmenulink_Button3)).setSelected(true);
				} else if (strBDWF.equals("BF")) {
					((Button) menutypeview.findViewById(R.id.bd_topmenulink_Button4)).setSelected(true);
				} else if (strBDWF.equals("BQC")) {
					((Button) menutypeview.findViewById(R.id.bd_topmenulink_Button5)).setSelected(true);
				}
			}

		});
		final TextView refres = (TextView) findViewById(R.id.top_title_refres);
		refres.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				LayoutInflater inflater = LayoutInflater.from(BDActivity.this);
				View menuview = inflater.inflate(R.layout.public_menulink02, null);

				m_popupWindow = new PopupWindow(menuview, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
				m_popupWindow.setBackgroundDrawable(new BitmapDrawable());
				m_popupWindow.setOutsideTouchable(true);
				m_popupWindow.showAtLocation(menuview, Gravity.RIGHT | Gravity.TOP, 0, 0);
				m_popupWindow.showAsDropDown(refres);

				menuview.setOnClickListener(new OnClickListener() {

					@Override
					public void onClick(View v) {
						// TODO Auto-generated method stub
						m_popupWindow.dismiss();
					}
				});

				Button public_menulink_Button01 = (Button) menuview.findViewById(R.id.public_menulink_Button01);
				public_menulink_Button01.setOnClickListener(new View.OnClickListener() {
					@Override
					public void onClick(View arg0) {
						m_popupWindow.dismiss();
						Intent intent;
						if (checkUserLogin()) {
							Intent intent0 = new Intent();
							intent0.putExtra("lotID", LotConstants.LOT_ID_BD);
							intent0.setClass(BDActivity.this, BetRecordActivity.class);
							startActivity(intent0);
						} else {
							intent = new Intent(getApplicationContext(), LoginActivity.class);
							startActivityForResult(intent, REQ_CODE_JCFOOT_LOGIN);
						}
					}
				});
				Button public_menulink_Button02 = (Button) menuview.findViewById(R.id.public_menulink_Button02);
				public_menulink_Button02.setVisibility(View.GONE);
				Button public_menulink_Button03 = (Button) menuview.findViewById(R.id.public_menulink_Button03);
				public_menulink_Button03.setOnClickListener(new View.OnClickListener() {
					@Override
					public void onClick(View arg0) {
						// TODO Auto-generated method stub
						m_popupWindow.dismiss();
						Intent intent;
						// if (checkUserLogin()) {
						intent = new Intent(getApplicationContext(), KjinfoBDResult.class);
						intent.putExtra("LotName", getString(R.string.kjinfo_number_bd_info));
						startActivity(intent);
						// } else {
						// intent = new Intent(
						// getApplicationContext(),
						// LoginActivity.class);
						// startActivityForResult(intent,
						// REQ_CODE_JCFOOT_LOGIN);
						// }
					}
				});
				Button public_menulink_Button04 = (Button) menuview.findViewById(R.id.public_menulink_Button04);
				public_menulink_Button04.setOnClickListener(new View.OnClickListener() {
					@Override
					public void onClick(View arg0) {
						// TODO Auto-generated method stub
						m_popupWindow.dismiss();
						// Intent intent;
						// intent = new Intent(getApplicationContext(),
						// HelpActivity.class);
						// startActivity(intent);
						Intent intent = new Intent(getApplicationContext(), CaiPiaoHelp.class);
						intent.putExtra("cp_title", "北京单场");
						intent.putExtra("cp_url", "bjdc.html");
						startActivity(intent);
					}
				});
			}
		});
	}

	/**
	 * 菜单玩法按钮事件
	 * 
	 * @param btnId
	 */
	protected void setBtnOnClickTopMenu(final int btnId) {
		Button btn = (Button) menutypeview.findViewById(btnId);
		btn.setOnClickListener(new View.OnClickListener() {
			public void onClick(View v) {
				try {
					menu_popupWindow.dismiss();
					setOrderFieldMenu(btnId);
					// 发送不同彩种网络请求
					top_title_tvplaytype.setText(strLot);
					// reset();

				} catch (Exception e) {
					// TODO Auto-generated catch block
					// e.printStackTrace();
				}
			}
		});

	}

	/**
	 * 获取玩法及改变按钮背景
	 * 
	 * @param btnId
	 */
	protected void setOrderFieldMenu(int btnId) {
		// 恢复默认
		((Button) menutypeview.findViewById(R.id.bd_topmenulink_Button1)).setSelected(false);
		((Button) menutypeview.findViewById(R.id.bd_topmenulink_Button2)).setSelected(false);
		((Button) menutypeview.findViewById(R.id.bd_topmenulink_Button3)).setSelected(false);
		((Button) menutypeview.findViewById(R.id.bd_topmenulink_Button4)).setSelected(false);
		((Button) menutypeview.findViewById(R.id.bd_topmenulink_Button5)).setSelected(false);
		switch (btnId) {
		case R.id.bd_topmenulink_Button1:
			strLot = "让球胜平负";
			((Button) menutypeview.findViewById(R.id.bd_topmenulink_Button1)).setSelected(true);
			strBDWF = "RQSPF";
			break;
		case R.id.bd_topmenulink_Button2:
			strLot = "总进球";
			((Button) menutypeview.findViewById(R.id.bd_topmenulink_Button2)).setSelected(true);
			strBDWF = "ZJQ";
			break;
		case R.id.bd_topmenulink_Button3:
			strLot = "上下单双";
			strBDWF = "SXDS";
			((Button) menutypeview.findViewById(R.id.bd_topmenulink_Button3)).setSelected(true);
			break;
		case R.id.bd_topmenulink_Button4:
			strLot = "比分";
			strBDWF = "BF";
			((Button) menutypeview.findViewById(R.id.bd_topmenulink_Button4)).setSelected(true);
			break;
		case R.id.bd_topmenulink_Button5:
			strLot = "半全场";
			strBDWF = "BQC";
			((Button) menutypeview.findViewById(R.id.bd_topmenulink_Button5)).setSelected(true);
			break;
		}

		clearData();
		// 获取比赛场次信息赋值给groups
		if (matchData != null) {
			if (matchData.size() != 0) {
				try {
					getMatchData();
					bdlist_adapter = new BaseGroupAdapter2(BDActivity.this, str_childs, strBDWF);
					bd_list.setAdapter(bdlist_adapter); // 绑定视图－适配器
				} catch (Exception e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}

				// jclist.expandGroup(0);
			} else {
				Toast.makeText(BDActivity.this, R.string.bdactivity_4, Toast.LENGTH_SHORT).show();
			}
		}
	}

	@Override
	public boolean onTouchEvent(MotionEvent event) {
		// TODO Auto-generated method stub
		if (m_popupWindow != null) {
			m_popupWindow.dismiss();
		}
		return super.onTouchEvent(event);
	}

	public boolean checkUserLogin() {
		return true == ApplicationData.getInstance().isUserLogin();
	}

	/**
	 * 清除用户选择的数据，恢复初始状态
	 */

	public void clearData() {
		// 清除数据
		if (str_childs != null) {
			// for (int i = 0; i < str_childs.size(); i++) {
			// 若children不为空，循环设置children的checked
			for (ChildDTO child : str_childs) {
				if (strBDWF.equals("RQSPF")) {
					child.str_sbtn = false;
					child.str_fbtn = false;
					child.str_pbtn = false;
					child.str_sp = "";
				} else if (strBDWF.equals("SXDS")) {
					child.str_sbtn = false;
					child.str_fbtn = false;
					child.str_pbtn = false;
					child.str_xsbtn = false;
					child.str_sp = "";
				} else if (strBDWF.equals("BQC")) {
					// 半全场赛果gridview是否显示
					child.setShowBQCGrid(false);
					child.str_sbtn = false;
					// 半全场赛果gridview按钮状态初始化
					List<String> list_gridview_selectstate = new ArrayList<String>();
					for (int k = 0; k < 9; k++) {// 半全场9中赛果
						list_gridview_selectstate.add("false");
					}
					child.setList_bqcgridview_selectstate(list_gridview_selectstate);
					child.setBtnBQCcontent("点击弹出下拉列表");
					List<String> list_gridview_selectcon = new ArrayList<String>();
					child.setList_bqcgridview_selectconcent(list_gridview_selectcon);
					// 半全场赛果gridview按钮SP list初始化
					List<String> list_gridview_selectsp = new ArrayList<String>();
					for (int k = 0; k < 9; k++) {// 半全场9中赛果sp
						list_gridview_selectsp.add("0");
					}
					child.setList_bqcgridview_selectsp(list_gridview_selectsp);
					child.setBqc_selectsp("");
				} else if (strBDWF.equals("ZJQ")) {
					// 总进球gridview按钮状态初始化
					List<String> list_gridview_selectstate = new ArrayList<String>();
					for (int k = 0; k < 8; k++) {// 总进球8种赛果
						list_gridview_selectstate.add("false");
					}
					child.setList_zjqgridview_selectstate(list_gridview_selectstate);
					child.setSelectZJQCG("");
					List<String> list_gridview_selectcon = new ArrayList<String>();
					child.setList_zjqgridview_selectconcent(list_gridview_selectcon);
					// 总进球gridview按钮sp list初始化
					List<String> list_gridview_selectsp = new ArrayList<String>();
					for (int k = 0; k < 8; k++) {// 总进球8种赛果sp
						list_gridview_selectsp.add("0");
					}
					child.setList_zjqgridview_selectsp(list_gridview_selectsp);
					child.setBqc_selectsp("");
				} else if (strBDWF.equals("BF")) {
					// 比分主胜gridview是否显示
					child.setShowBFS(false);
					child.setShowBFP(false);
					child.setShowBFF(false);
					// 设置按钮选择状态为未选择
					child.setStr_sbtn(false);
					child.setStr_fbtn(false);
					child.setStr_pbtn(false);
					// 比分主胜gridview按钮状态初始化
					List<String> list_bfsgridview_selectstate = new ArrayList<String>();
					for (int k = 0; k < 10; k++) {// 比分主胜10种赛果
						list_bfsgridview_selectstate.add("false");
					}
					child.setList_bfsgridview_selectstate(list_bfsgridview_selectstate);
					// 比分平gridview按钮状态初始化
					List<String> list_bfpgridview_selectstate = new ArrayList<String>();
					for (int k = 0; k < 5; k++) {// 比分平5种赛果
						list_bfpgridview_selectstate.add("false");
					}
					child.setList_bfpgridview_selectstate(list_bfpgridview_selectstate);
					// 比分主负gridview按钮状态初始化
					List<String> list_bffgridview_selectstate = new ArrayList<String>();
					for (int k = 0; k < 10; k++) {// 比分主负10种赛果
						list_bffgridview_selectstate.add("false");
					}
					child.setList_bffgridview_selectstate(list_bffgridview_selectstate);
					// 设置按钮初始文字内容
					child.setBtnbfscontent("主胜");
					child.setBtnbfpcontent("平局");
					child.setBtnbffcontent("主负");
					// 比分主胜gridview按钮选择内容初始化
					List<String> list_bfsgridview_selectconcent = new ArrayList<String>();
					child.setList_bfsgridview_selectconcent(list_bfsgridview_selectconcent);
					// 比分平gridview按钮选择内容初始化
					List<String> list_bfpgridview_selectconcent = new ArrayList<String>();
					child.setList_bfpgridview_selectconcent(list_bfpgridview_selectconcent);
					// 比分主负gridview按钮选择内容初始化
					List<String> list_bffgridview_selectconcent = new ArrayList<String>();
					child.setList_bffgridview_selectconcent(list_bffgridview_selectconcent);
					child.setBtnbfAllcontent("");
					// 比分sp值选择list初始化
					List<String> list_bfsgridview_selectsp = new ArrayList<String>();
					for (int k = 0; k < 10; k++) {// 比分主胜10种赛果SP
						list_bfsgridview_selectsp.add("0");
					}
					child.setList_bfsgridview_selectsp(list_bfsgridview_selectsp);

					List<String> list_bfpgridview_selectsp = new ArrayList<String>();
					for (int k = 0; k < 5; k++) {// 比分平5种赛果SP
						list_bfpgridview_selectsp.add("0");
					}
					child.setList_bfpgridview_selectsp(list_bfpgridview_selectsp);

					List<String> list_bffgridview_selectsp = new ArrayList<String>();
					for (int k = 0; k < 10; k++) {// 比分主负10种赛果SP
						list_bffgridview_selectsp.add("0");
					}
					child.setList_bffgridview_selectsp(list_bffgridview_selectsp);
					child.setBqc_selectsp("");
				}
			}
			ArrayList<ChildDTO> list_jcdto = new ArrayList<ChildDTO>();
			ApplicationData.getInstance().setList_jcdto(list_jcdto);

			bdlist_adapter.notifyDataSetChanged();
			tv_selectNum.setText(Html.fromHtml("已经选择" + "<font color=#a50000>" + 0 + "</font>" + "场比赛"));
			// }
		}
	}

	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		if (keyCode == KeyEvent.KEYCODE_BACK) {
			if(ifPush){
				Intent intent = new Intent(this, JddMainActivity.class);
				startActivity(intent);
			}
			// 跳转至-开奖信息主页面
			this.finish();
			return true;
		} else {
			return super.onKeyDown(keyCode, event);
		}
	};

	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		if (requestCode == REQ_CODE_BUYMAIN && resultCode == RESULT_OK) {
			onKeyDown(KeyEvent.KEYCODE_BACK, null);
		}
		// 从投注记录回退时，需要清除数据
		if (resultCode == 0) {
			// clearData();
		}
		if (resultCode == RESULT_CANCELED) {
			if (requestCode == REQ_CODE_BD) {
				clearData();
			}
		}
		if (resultCode == RESULT_OK) {
			if (requestCode == REQ_CODE_BD_LOGIN) {
				bdSubmit();
			} else if (requestCode == REQ_CODE_BD) {
				onKeyDown(KeyEvent.KEYCODE_BACK, null);
			} else {
				// clearData();//登陆
			}
		}
		if (resultCode == 110) {
			onKeyDown(KeyEvent.KEYCODE_BACK, null);
		}
	};

	@Override
	public void finish() {
		// TODO Auto-generated method stub
		super.finish();
		try {
			// loadIssueInfo.cancel(true);
			// loadIssueDetail.cancel(true);
			asyncloader.cancel(true);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			// e.printStackTrace();
		}
	};

	class FootBallHHTZAdapter extends BaseExpandableListAdapter implements Serializable {

		/**
		 * 
		 */
		private static final long serialVersionUID = 1L;
		private Context context; // 父activity
		LayoutInflater inflater;
		private ArrayList<GroupDTO> datas;
		private Map<String, Integer> sel = new HashMap<String, Integer>();

		public FootBallHHTZAdapter(Context c, List<GroupDTO> datas) {
			context = c;
			sel.clear();
			inflater = (LayoutInflater) c.getSystemService(LAYOUT_INFLATER_SERVICE);
			this.datas = (ArrayList<GroupDTO>) datas;
		}

		public int getSelNum() {
			return (sel.isEmpty() ? 0 : sel.size());
		}

		public void clearSel() {
			for (GroupDTO gto : datas) {
				for (ChildDTO cto : gto.children) {
					cto.hhtzzq1 = "";
					cto.hhtzzq2 = "";
					cto.hhtzzq3 = "";
					cto.hhtzzq4 = "";
					cto.hhtzzq5 = "";
				}
			}
			sel.clear();
			this.notifyDataSetChanged();
		}

		public void refreshWithData(int gid, int cid, ChildDTO cDto) {
			datas.get(gid).children.remove(cid);
			datas.get(gid).children.add(cid, cDto);
			this.notifyDataSetChanged();
		}

		public ArrayList<GroupDTO> getDatas() {
			return datas;
		}

		@Override
		public Object getChild(int groupPosition, int childPosition) {
			// TODO Auto-generated method stub
			return datas.get(groupPosition).children.get(childPosition);
		}

		@Override
		public long getChildId(int groupPosition, int childPosition) {
			// TODO Auto-generated method stub
			return childPosition;
		}

		@Override
		public View getChildView(final int groupPosition, final int childPosition, boolean isLastChild,
				View convertView, ViewGroup parent) {
			// TODO Auto-generated method stub
			ChildExpandableListHolder holder = null; // 清空临时变量
			if (convertView == null) { // 若行未初始化
				// 通过flater初始化行视图
				convertView = inflater.inflate(R.layout.jdd_jclq_rf_sf_dxf_item, null);
				// 并将行视图的5个子视图引用放到tag中
				holder = new ChildExpandableListHolder();
				holder.tv_item_no_endtimes = (TextView) convertView.findViewById(R.id.tv_item_no_endtimes);
				holder.tv_item_no_endtime = (TextView) convertView.findViewById(R.id.tv_item_no_endtime);
				holder.textView_matchname = (TextView) convertView.findViewById(R.id.tv_item_match_name);
				holder.tv_hTeam = (TextView) convertView.findViewById(R.id.tv_item_vteam);
				holder.tv_vTeam = (TextView) convertView.findViewById(R.id.tv_item_hteam);
				holder.btn_rf = (Button) convertView.findViewById(R.id.btn_item_rf);
				holder.view_line_rf = convertView.findViewById(R.id.btn_item_rf_line);
				holder.view_line_zs = convertView.findViewById(R.id.btn_item_rf_line_zs);
				holder.btn_zf = (Button) convertView.findViewById(R.id.btn_item_s);
				holder.btn_zs = (Button) convertView.findViewById(R.id.btn_item_f);
				convertView.setTag(holder);
			} else { // 若行已初始化，直接从tag属性获得子视图的引用
				holder = (ChildExpandableListHolder) convertView.getTag();
			}

			final GroupDTO info1 = this.datas.get(groupPosition);
			// 获得行数据（模型）
			final String wkn = DateUtil.getTName(info1.title);
			final ChildDTO info = this.datas.get(groupPosition).children.get(childPosition);
			if (info != null) {
				String str_nmu = "";
				// 根据模型数据，设置行视图的控件值
				if (info.nMm.length() < 4) {
					str_nmu = info.nMm;
				} else {
					str_nmu = info.nMm.substring(0, 4);
				}
				holder.tv_item_no_endtimes.setText((info.mId).substring(6) + DateUtil.getDateTime1(info.eTime));// 130718301
				holder.tv_item_no_endtime.setText((info.mId).substring(6) + DateUtil.getDateTime1(info.eTime));// 130718301
				holder.tv_hTeam.setText(info.hTeam);
				holder.tv_vTeam.setText(info.vTeam);
				holder.textView_matchname.setText(str_nmu);
				holder.btn_zs.setVisibility(View.GONE);
				holder.view_line_zs.setVisibility(View.GONE);
				String btnName = "";
				if (!TextUtils.isEmpty(info.hhtzzq1)) {
					if (info.hhtzzq1.length() >= 1) {
						btnName += " 胜平负:";
						if (info.hhtzzq1.contains("3")) {
							btnName += " 胜";
						}
						if (info.hhtzzq1.contains("1")) {
							btnName += " 平";
						}
						if (info.hhtzzq1.contains("0")) {
							btnName += " 负";
						}
					}
				}
				if (!TextUtils.isEmpty(info.hhtzzq2)) {
					if (info.hhtzzq2.length() >= 1) {
						btnName += " 让球胜平负:";
						if (info.hhtzzq2.contains("3")) {
							btnName += " 胜";
						}
						if (info.hhtzzq2.contains("1")) {
							btnName += " 平";
						}
						if (info.hhtzzq2.contains("0")) {
							btnName += " 负";
						}
					}
				}
				if (!TextUtils.isEmpty(info.hhtzzq3)) {
					// Log.d("jcfoot adap", "info.hhtzzq3= "+info.hhtzzq3);
					if (info.hhtzzq3.length() >= 1) {
						btnName += " 半全场:";
						if (info.hhtzzq3.contains("a")) {
							btnName += " 胜胜";
						}
						if (info.hhtzzq3.contains("b")) {
							btnName += " 胜平";
						}
						if (info.hhtzzq3.contains("c")) {
							btnName += " 胜负";
						}
						if (info.hhtzzq3.contains("d")) {
							btnName += " 平胜";
						}
						if (info.hhtzzq3.contains("e")) {
							btnName += " 平平";
						}
						if (info.hhtzzq3.contains("f")) {
							btnName += " 平负";
						}
						if (info.hhtzzq3.contains("g")) {
							btnName += " 负胜";
						}
						if (info.hhtzzq3.contains("h")) {
							btnName += " 负平";
						}
						if (info.hhtzzq3.contains("i")) {
							btnName += " 负负";
						}
					}
				}
				if (!TextUtils.isEmpty(info.hhtzzq4)) {
					if (info.hhtzzq4.length() >= 1) {
						btnName += " 总进球:";
						if (info.hhtzzq4.contains("0")) {
							btnName += " 0";
						}
						if (info.hhtzzq4.contains("1")) {
							btnName += " 1";
						}
						if (info.hhtzzq4.contains("2")) {
							btnName += " 2";
						}
						if (info.hhtzzq4.contains("3")) {
							btnName += " 3";
						}
						if (info.hhtzzq4.contains("4")) {
							btnName += " 4";
						}
						if (info.hhtzzq4.contains("5")) {
							btnName += " 5";
						}
						if (info.hhtzzq4.contains("6")) {
							btnName += " 6";
						}
						if (info.hhtzzq4.contains("7")) {
							btnName += " 7+";
						}
					}
				}
				if (!TextUtils.isEmpty(info.hhtzzq5)) {
					if (info.hhtzzq5.length() >= 1) {
						btnName += " 比分:";
						if (info.hhtzzq5.contains("a")) {
							btnName += " 1:0";
						}
						if (info.hhtzzq5.contains("b")) {
							btnName += " 2:0";
						}
						if (info.hhtzzq5.contains("c")) {
							btnName += " 2:1";
						}
						if (info.hhtzzq5.contains("d")) {
							btnName += " 3:0";
						}
						if (info.hhtzzq5.contains("e")) {
							btnName += " 3:1";
						}
						if (info.hhtzzq5.contains("f")) {
							btnName += " 3:2";
						}
						if (info.hhtzzq5.contains("g")) {
							btnName += " 4:0";
						}
						if (info.hhtzzq5.contains("h")) {
							btnName += " 4:1";
						}
						if (info.hhtzzq5.contains("i")) {
							btnName += " 4:2";
						}
						if (info.hhtzzq5.contains("j")) {
							btnName += " 5:0";
						}
						if (info.hhtzzq5.contains("k")) {
							btnName += " 5:1";
						}
						if (info.hhtzzq5.contains("l")) {
							btnName += " 5:2";
						}
						if (info.hhtzzq5.contains("m")) {
							btnName += " 胜其他";
						}
						if (info.hhtzzq5.contains("n")) {
							btnName += " 0:0";
						}
						if (info.hhtzzq5.contains("o")) {
							btnName += " 1:1";
						}
						if (info.hhtzzq5.contains("p")) {
							btnName += " 2:2";
						}
						if (info.hhtzzq5.contains("q")) {
							btnName += " 3:3";
						}
						if (info.hhtzzq5.contains("r")) {
							btnName += " 平其他";
						}
						if (info.hhtzzq5.contains("s")) {
							btnName += " 0:1";
						}
						if (info.hhtzzq5.contains("t")) {
							btnName += " 0:2";
						}
						if (info.hhtzzq5.contains("u")) {
							btnName += " 1:2";
						}
						if (info.hhtzzq5.contains("v")) {
							btnName += " 0:3";
						}
						if (info.hhtzzq5.contains("w")) {
							btnName += " 1:3";
						}
						if (info.hhtzzq5.contains("x")) {
							btnName += " 2:3";
						}
						if (info.hhtzzq5.contains("y")) {
							btnName += " 0:4";
						}
						if (info.hhtzzq5.contains("z")) {
							btnName += " 1:4";
						}
						if (info.hhtzzq5.contains("1")) {
							btnName += " 2:4";
						}
						if (info.hhtzzq5.contains("2")) {
							btnName += " 0:5";
						}
						if (info.hhtzzq5.contains("3")) {
							btnName += " 1:5";
						}
						if (info.hhtzzq5.contains("4")) {
							btnName += " 2:5";
						}
						if (info.hhtzzq5.contains("5")) {
							btnName += " 负其他";
						}
					}
				}
				String key = groupPosition + "" + childPosition;
				if (btnName.length() >= 2) {
					holder.btn_zf.setText(btnName.length() > 16 ? btnName.substring(0, 16) + "..." : btnName);
					holder.btn_zf.setSelected(true);
					if (sel.containsKey(key) == false) {
						sel.put(key, 1);
					}
				} else {
					holder.btn_zf.setText("选择赛事方案");
					holder.btn_zf.setSelected(false);
					if (sel.containsKey(key) == true) {
						sel.remove(key);
					}
				}
				holder.btn_zf.setTag(info);
				holder.btn_zf.setOnClickListener(new OnClickListener() {

					@Override
					public void onClick(View arg0) {
						// TODO Auto-generated method stub
						Intent intent = new Intent(BDActivity.this, JczqHhtz.class);
						intent.putExtra("info", info);
						intent.putExtra("wk", wkn);
						intent.putExtra("gindex", groupPosition);
						intent.putExtra("cindex", childPosition);
						startActivityForResult(intent, REQ_CODE_LQHHTZ);
					}
				});
			}
			return convertView;

		}

		@Override
		public int getChildrenCount(int groupPosition) {
			// TODO Auto-generated method stub
			if (datas.size() <= 0) {
				return 0;
			}
			return datas.get(groupPosition).children.size();
		}

		@Override
		public Object getGroup(int groupPosition) {
			// TODO Auto-generated method stub
			return datas.get(groupPosition);
		}

		@Override
		public int getGroupCount() {
			// TODO Auto-generated method stub
			return datas.size();
		}

		@Override
		public long getGroupId(int groupPosition) {
			// TODO Auto-generated method stub
			return groupPosition;
		}

		@Override
		public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
			// TODO Auto-generated method stub
			GroupExpandableListHolder holder = null;
			if (convertView == null) {
				convertView = inflater.inflate(R.layout.item_group, null);
				holder = new GroupExpandableListHolder();
				holder.title = (TextView) convertView.findViewById(R.id.item_group_title);
				holder.indicator = (ImageView) convertView.findViewById(R.id.item_group_status);
				convertView.setTag(holder);
			} else {
				holder = (GroupExpandableListHolder) convertView.getTag();
			}
			// 未完成
			GroupDTO info = this.datas.get(groupPosition);
			if (info != null) {
				// 根据模型值设置textview的文本
				holder.title.setText(DateUtil.getTName(info.title));
			}
			if (true == isExpanded) {
				holder.indicator.setImageResource(R.drawable.jdd_item_open);
			} else {
				holder.indicator.setImageResource(R.drawable.jdd_item_close);
			}
			return convertView;
		}

		@Override
		public boolean hasStableIds() {
			// TODO Auto-generated method stub
			return false;
		}

		@Override
		public boolean isChildSelectable(int groupPosition, int childPosition) {
			// TODO Auto-generated method stub
			return false;
		}

		// 定义一个内部类，用于保存父View
		private class GroupExpandableListHolder {
			TextView title;
			ImageView indicator;
		}

		// 定义一个内部类，用于保存子View
		private class ChildExpandableListHolder {
			TextView tv_item_no_endtime, textView_matchname, tv_vTeam, tv_hTeam,tv_item_no_endtimes;
			Button btn_rf;
			Button btn_zf;// 胜
			Button btn_zs;// 负
			View view_line_rf;
			View view_line_zs;
		}
	}

}
